<?php
/**
 * Galdic project
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Galdic
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Admin_IdsController
 * 
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: IdsController.php 1 2009-09-14 16:49:04Z vifito $
 */
class Admin_IdsController extends Zend_Controller_Action
{
    /**
     * Check session
     */
    public function preDispatch()
    {
        $session = Zend_Registry::get('session');
        $actionName = $this->getRequest()->getActionName();
        
        if(!isset($session->username) && ($actionName!='login')) {
            $this->_redirect('/admin/user/login/');
        } elseif( isset($session->username) ) {
            $this->view->username = $session->username;
        }
    }

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->title = "IDS";
        $this->view->headTitle($this->view->title, 'PREPEND');
        
        $intrusions = new Admin_Model_DbTable_Ids();
        $rows = $intrusions->fetchAll(null);
        $paginator = Zend_Paginator::factory($rows);
        
        $page = $this->_request->getParam('page');
        $paginator->setCurrentPageNumber($page);

        $this->view->intrusions = $paginator;
        
        //$this->view->assign('intrusions', $intrusions->fetchAll(null));
    }

    public function deleteAction()
    {
        $this->view->title = "Eliminar Intrusión";
        $this->view->headTitle($this->view->title, 'PREPEND');
        
        if($this->getRequest()->isPost()) {
            $action = $this->getRequest()->getPost('action');                        
            if($action == 'Si') {
                $id = $this->getRequest()->getPost('id');
                
                $intrusion = new Admin_Model_DbTable_Ids();
                $intrusion->delete('`id`='.(int)$id);                                
            }
                
            $this->_redirect('/admin/ids/'); // Listado de intrusiones
        } else {
            $id = $this->_getParam('id', 0);
            $intrusion = new Admin_Model_DbTable_Ids();
            $this->view->intrusion = $intrusion->fetchRow('`id`='.(int)$id);
        }
    }


}





